package pers.hl.module_main.publish

import com.amap.api.maps2d.model.LatLng
import pers.hl.lib_global.common.Const
import pers.hl.lib_global.http.LibResponse
import pers.hl.lib_global.model.bean.Book
import pers.hl.lib_global.model.bean.BookTag
import pers.hl.lib_global.model.bean.DoubanBook
import pers.hl.lib_global.model.bean.Library
import pers.hl.lib_global.mvvm.BaseLibModel

class PublishModel: BaseLibModel() {

    suspend fun getAllTags(): LibResponse<List<BookTag>> {
        return libService.allBookTags()
    }

    suspend fun addBook(book: Book): LibResponse<*> {
        return libService.addBook(book)
    }

    suspend fun fetchNearByLibraries(curPos: LatLng): LibResponse<List<Library>> {
        return libService.fetchNearByLibraries(curPos.latitude, curPos.longitude)
    }

    suspend fun getDoubanBook(isbnCode: Long): LibResponse<*> {
        val url = String.format(
            "https://api.douban.com/v2/book/isbn/%s?apikey=%s",
            isbnCode,
            Const.API_KEY_DOUBAN
        )
        return libService.getDouBanBook(url)
    }

    suspend fun getAllLibraries(): LibResponse<List<Library>> {
        return libService.getAllLibraries(1000)
    }
}